package dhm.com.hpx.activity;

import android.app.ProgressDialog;
import android.graphics.Canvas;
import android.widget.Toast;

import com.lidong.pdf.PDFView;
import com.lidong.pdf.listener.OnDrawListener;
import com.lidong.pdf.listener.OnLoadCompleteListener;
import com.lidong.pdf.listener.OnPageChangeListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import dhm.com.hpx.R;
import dhm.com.hpx.base.BaseActivity;
import dhm.com.hpx.base.netWork.Constant;

public class PdfActivity extends BaseActivity implements OnPageChangeListener, OnDrawListener, OnLoadCompleteListener {

    @BindView(R.id.pdfView)
    PDFView pdfView;

    @Override
    protected int getLayout() {
        return R.layout.activity_pdf;
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        displayFromFile1(Constant.PATH+"upload/quqikes.pdf","quqikes.pdf");
    }

    @Override
    protected void initData() {

    }


    /**
     * 获取打开网络的pdf文件
     * @param fileUrl
     * @param fileName
     */
    private void displayFromFile1( String fileUrl ,String fileName) {
        //设置pdf文件地址
        Toast.makeText(this, "报告加载中,请等待。。。", Toast.LENGTH_SHORT).show();
        pdfView.fileFromLocalStorage(this,this,this,fileUrl,fileName);

    }

    /**
     * 翻页回调
     * @param page
     * @param pageCount
     */
    @Override
    public void onPageChanged(int page, int pageCount) {
    }
    /**
     * 加载完成回调
     * @param nbPages 总共的页数
     */
    @Override
    public void loadComplete(int nbPages) {

    }
    @Override
    public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {
        // Toast.makeText( MainActivity.this , "pageWidth= " + pageWidth + "
        // pageHeight= " + pageHeight + " displayedPage=" + displayedPage , Toast.LENGTH_SHORT).show();
    }
    /**
     * 显示对话框
     */
    private void showProgress(){
//        showProgressDialog();
    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
//        dissmissProgressDialog();
    }


    private ProgressDialog progDialog = null;// 搜索时进度条

    /**
     * 显示进度框
     */
    private void showProgressDialog() {
        if (progDialog == null) {
            progDialog = new ProgressDialog(this);
        }
        progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progDialog.setIndeterminate(false);
        progDialog.setCancelable(false);
        progDialog.setMessage("报告加载中,请等待。。。");
        progDialog.show();
    }

    /**
     * 隐藏进度框
     */
    private void dissmissProgressDialog() {
        if (progDialog != null) {
            progDialog.dismiss();
        }
    }


}
